{include file='public:header-css'/}
<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        {include file='public:left-menu'/}
        <!--End 左侧导航-->
        <!--头部信息-->
        {include file='public:nav-header' title="系统管理" subTitle="底部导航"/}
        <!--End 头部信息-->
        <!--页面主要内容-->
        <main class="lyear-layout-content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-body">
                                <form class="layui-form" lay-filter="tabbarForm" method="post" action="">
                                    <input type="hidden" name="id" value="{$info.id}">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">名称</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="name" maxlength="4" value="{$info.name}" lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">未选中图片</label>
                                        <div class="layui-input-block">
                                            <img class="upload-img" id="unselect_image" src="{$info.unselect_image|default='__STATIC__/images/upload.png'}">
                                            <input type="hidden" name="unselect_image" value="{$info.unselect_image}">
                                            <div class="input-group-btn">
                                                <button onclick="GetUploadify(1,'unselect_image','logo','callback')" class="btn btn-default" type="button">上传图片</button>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">选中图片</label>
                                        <div class="layui-input-block">
                                            <img class="upload-img" id="selected_image" src="{$info.selected_image|default='__STATIC__/images/upload.png'}">
                                            <input type="hidden" name="selected_image" lay-verify="required" value="{$info.selected_image}">
                                            <div class="input-group-btn">
                                                <button onclick="GetUploadify(1,'selected_image','logo','callback')" class="btn btn-default" type="button">上传图片</button>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">跳转类型</label>
                                        <div class="layui-input-block">
                                            <select lay-filter="jump_type" name="jump_type" lay-verify="required">
                                                <option value="">请选择跳转类型</option>
                                                <option value="0">不跳转</option>
                                                <option value="1">内部页面</option>
                                                <option value="2">H5</option>
                                                <option value="3">外部小程序</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">路径</label>
                                        <div class="layui-input-block">
                                            <div class="select-div {if $info.jump_type != 1}layui-hide{/if}">
                                                <select layui-filter="select_path" name="select_path" value="{$info.path}">
                                                    <option value="">请选择跳转路径</option>
                                                    {volist name="pages" id="vo" }
                                                    <option value="{$key}">{$vo}</option>
                                                    {/volist}
                                                </select>
                                            </div>
                                            <input layui-filter="path" type="text" name="path" value="{$info.path}" placeholder="请输入路径" autocomplete="off" class="layui-input {if $info.jump_type != 2 && $info.jump_type != 3}layui-hide{/if}">
                                        </div>
                                    </div>
                                    <div class="layui-form-item appid">
                                        <label class="layui-form-label">应用ID</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="app_id" value="{$info.app_id}" placeholder="请输入应用ID" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <!--                                    <div class="layui-form-item">-->
                                    <!--                                        <label class="layui-form-label">附加数组</label>-->
                                    <!--                                        <div class="layui-input-block">-->
                                    <!--                                            <textarea name="extra_array" placeholder="请输入附加数组" class="layui-textarea"></textarea>-->
                                    <!--                                        </div>-->
                                    <!--                                    </div>-->
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">权重</label>
                                        <div class="layui-input-block">
                                            <input type="number" name="weigh" placeholder="请输入权重" value="{$info.weigh}" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">状态</label>
                                        <div class="layui-input-block">
                                            <input type="radio" name="status" value="0" title="禁用" {if $info.status== 0}checked{/if}>
                                            <input type="radio" name="status" value="1" title="启用" {if $info.status== 1}checked{/if}>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-input-block">
                                            <button class="layui-btn" lay-submit lay-filter="submitForm">提交</button>
                                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </main>
        <!--End 页面主要内容-->
    </div>
</div>
<!--图片预览插件-->
<script type="text/javascript">
    layui.use('form', function () {
        var form = layui.form;

        //监听提交
        form.on('submit(submitForm)', function (data) {
            console.info(data.field)
            try {
                switch (data.field.jump_type) {
                    case '1':
                        form.val('tabbarForm', {
                            path: data.field.select_path
                        })
                    case '2':
                        if (!data.field.path) {
                            throw new Error('请选择路径')
                        }
                        break
                    case '3':
                        if (!data.field.select_path) {
                            throw new Error('请选择路径')
                        }
                        if (!data.field.app_id) {
                            throw new Error('请填写应用ID')
                        }
                        break
                }
            } catch (e) {
                layer.msg(e.message)
                return false
            }
        });

        form.on('select(jump_type)', function (data) {
            if (data.value == 2 || data.value == 3) {
                $('.select-div').addClass('layui-hide')
                $('input[name="path"]').removeClass('layui-hide')
            } else {
                $('.select-div').removeClass('layui-hide')
                $('input[name="path"]').addClass('layui-hide')
            }
        });

        form.val('tabbarForm', {
            'select_path': '{$info.path}',
            'path': '{$info.path}',
            'jump_type': '{$info.jump_type}',
        })

        form.render()
    });

    function callback(fileurl_tmp, fileurl_id) {
        $("[name=" + fileurl_id + "]").val(fileurl_tmp);
        $("#" + fileurl_id).attr('src', fileurl_tmp);
    }
</script>
</body>
</html>
